package com.ruoyi.web.controller.api;

import com.ruoyi.cems.service.IBmsEmergencyNoticeService;
import com.ruoyi.cems.service.IBmsEmergencyVariableControlService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(description = "蓝信接口")
@RestController
@RequestMapping("/api/lx")
public class LXController extends BaseController {
    @Autowired
    private IBmsEmergencyVariableControlService bmsEmergencyVariableControlService;

    @Autowired
    private IBmsEmergencyNoticeService bmsEmergencyNoticeService;


    @PostMapping("/data_num")
    public AjaxResult data_num(@ApiParam(value = "请求参数") @RequestBody Map<String, String> params) {
        String startTime = params.get("start_time");
        String endTime = params.get("end_time");
        String systemCode = params.get("system_code");
        String dataType = params.get("data_type");
        // 判断 start_time 和 end_time 是否为空字符串
        if (startTime == null || startTime.trim().isEmpty() ||
                endTime == null || endTime.trim().isEmpty()) {
            return error("开始时间和结束时间不能为空");
        }

        if ("YJGL".equals(systemCode)){
            if("emergency_variable_control".equals(dataType)) {
                Map<String, Object> data = new HashMap<>();
                data.put("data_type", dataType);
                data.put("system_code", systemCode);
                data.put("group","");
                data.put("data_num", bmsEmergencyVariableControlService.selectBmsEmergencyVariableControlCount(startTime, endTime));
                return success(data);
            }else if ("emergency_notice".equals(dataType)){
                Map<String, Object> data = new HashMap<>();
                data.put("data_type", dataType);
                data.put("system_code", systemCode);
                data.put("group","");
                data.put("data_num", bmsEmergencyNoticeService.selectBmsEmergencyNotice(startTime,endTime));
                return success(data);
            }else{
                return error("数据类型错误");
            }
        }else{
            return error("系统编码错误");
        }
    }


    @PostMapping("/data_total_num")
    public AjaxResult data_total_num(@ApiParam(value = "请求参数", required = true) @RequestBody Map<String, String> params){
        String systemCode = params.get("system_code");
        String dataType = params.get("data_type");
        if ("YJGL".equals(systemCode)){
            if ("emergency_variable_control".equals(dataType)) {
                Map<String, Object> data = new HashMap<>();
                data.put("data_type", dataType);
                data.put("system_code", systemCode);
                data.put("group","");
                data.put("data_num", bmsEmergencyVariableControlService.selectBmsEmergencyVariableControlCount(null, null));
                return success(data);
            }else if ("emergency_notice".equals(dataType)){
                Map<String, Object> data = new HashMap<>();
                data.put("data_type", dataType);
                data.put("system_code", systemCode);
                data.put("group","");
                data.put("data_num", bmsEmergencyNoticeService.selectBmsEmergencyNotice(null,null));
                return success(data);
            }else{
                return error("数据类型错误");
            }
        }else{
            return error("系统编码错误");
        }
    }
}
